package com.kasinf.sample.datapermission.config;

import cn.hutool.core.util.DesensitizedUtil;
import com.kasinf.framework.common.pojo.security.DataRuleDTO;
import com.kasinf.framework.common.pojo.security.FieldRuleDTO;
import com.kasinf.framework.common.pojo.security.UserDataRulesDTO;
import com.kasinf.framework.datapermission.define.DataPermissionProcessor;
import com.kasinf.framework.datapermission.stamp.DataRuleKey;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : Kaiser
 * @Date: 2025/5/20  16:38
 */
@Component
public class SampleDataPermissionProcessor implements DataPermissionProcessor {
    @Override
    public Map<String, UserDataRulesDTO> queryUserDataRules(DataRuleKey key) {
        Map<String, UserDataRulesDTO> map = new HashMap<>();
        UserDataRulesDTO rules = new UserDataRulesDTO();
        List<DataRuleDTO> dataRules = new ArrayList<>();
        DataRuleDTO rule = new DataRuleDTO();
        rule.setRuleName("过滤正常用户");
        rule.setRuleColumn("status");
        rule.setRuleValue("1");
        rule.setRuleConditions("eq");
        dataRules.add(rule);
        List<FieldRuleDTO> fieldRules = new ArrayList<>();
        FieldRuleDTO fieldRule = new FieldRuleDTO();
        fieldRule.setFieldName("phone");
        fieldRule.setFieldColumn("phone");
        fieldRule.setDesRule(DesensitizedUtil.DesensitizedType.MOBILE_PHONE);
        fieldRule.setVisible(true);
        fieldRule.setSearchable(false);
        fieldRules.add(fieldRule);
        rules.setDataRules(dataRules);
        rules.setFieldRules(fieldRules);
        // 添加演示权限
        map.put("userList", rules);
        return map;
    }
}
